﻿@{
    var formBuilder = (FormBuilderModel)Model;
}
@if (formBuilder.MenuConfig != null && formBuilder.MenuConfig.Fields != null && formBuilder.MenuConfig.Fields.Count > 0)
{
    foreach (var field in formBuilder.MenuConfig.Fields)
    {
        var fieldId = $"{formBuilder.Prefix}_{field.Name.ToLower()}";
<form-item label="@field.Title" label-for="@fieldId" :required="@field.Required.ToString().ToLower()">
    @if (field.Type == MenuFieldType.Text.ToString())
    {
        <input type="text" name="@field.Name" id="@fieldId" @Html.GetString(field.Required, "required", "")>
    }
    else if (field.Type == MenuFieldType.InputEditor.ToString())
    {
        <Input-editor ref="@field.Name.ToLower()" name="@field.Name" :required="@field.Required.ToString().ToLower()"></Input-editor>
    }
    else if (field.Type == MenuFieldType.Select.ToString())
    {
        <select name="@field.Name" id="@fieldId" style="width:100%" @Html.GetString(field.Multiple, "multiple", "") @Html.GetString(field.Required, "required", "") placeholder="点击选择...">
            @foreach (var item in (List<JsonData<string>>)ViewData[field.Name])
            {
                <option value="@item.id">@item.text</option>
            }
        </select>
    }
    else if (field.Type == MenuFieldType.TreeSelect.ToString())
    {
        <i-select name="@field.Name" id="@fieldId" :options='@Html.ToJson(ViewData[field.Name])' @Html.GetString(field.Required, "required", "") tree style="width:100%"></i-select>
    }
    else if (field.Type == MenuFieldType.SelectInput.ToString())
    {
        <i-select name="@field.Name" id="@fieldId" :options='@Html.ToJson(ViewData[field.Name])' @Html.GetString(field.Multiple, "multiple", "") @Html.GetString(field.Required, "required", "") taggable style="width:100%"></i-select>
    }
    else if (field.Type == MenuFieldType.Tag.ToString())
    {
        <input type="text" name="@field.Name" placeholder="输入后回车" data-role="tagsinput" id="@fieldId" />
    }
    else if (field.Type == MenuFieldType.Image.ToString() || field.Type == MenuFieldType.File.ToString() || field.Type == MenuFieldType.Video.ToString())
    {
        if (field.MinCount == 0 && field.Required)
        {
            field.MinCount = 1;
        }
        if (field.MaxCount == 0)
        {
            field.MaxCount = 1;
        }
        if (field.Type == MenuFieldType.Image.ToString())
        {
            <Upload name="@field.Name" :format="['png','jpg']" :min="@field.MinCount" :max="@field.MaxCount" :max-size="@Html.GetString(field.MaxLength > 0, (field.MaxLength * 1024).ToString(), "2048")">
                @if (!string.IsNullOrEmpty(field.Remark))
                {
                    <div slot="tip" class="tooltip-text">@Html.Raw(field.Remark)</div>
                }
            </Upload>
            @*<UploadImage ref="@field.Name.ToLower()" name="@field.Name" :min="@field.MinCount" :max="@field.MaxCount" :maxLength="@Html.GetString(field.MaxLength > 0, (field.MaxLength * 1024).ToString(), "2048")" tooltip="@field.Remark" />*@
        }
        else if (field.Type == MenuFieldType.File.ToString())
        {
            <Upload name="@field.Name" :format='@Html.ToJson(string.IsNullOrEmpty(field.Format)?new string[0]:field.Format.Split(','))' :min="@field.MinCount" :max="@field.MaxCount" ::max-size="@Html.GetString(field.MaxLength > 0, (field.MaxLength * 1024).ToString(), "2048")">
                @if (!string.IsNullOrEmpty(field.Remark))
                {
                    <div slot="tip" class="tooltip-text">@Html.Raw(field.Remark)</div>
                }
            </Upload>
        }
        else
        {
            <div class="am-u-sm-2" style="padding-left:0;padding-right:0">
                <select v-model="videoType" name="VideoSource" data-ignore><option value="2" selected>上传视频</option><option value="1">视频链接</option></select>
            </div>
            <div class="am-u-sm-10" style="padding-right:0">
                <input v-if="videoType==='1'" type="text" name="@field.Name" placeholder="请输入视频链接..." />
                <Upload v-else ref="@field.Name.ToLower()" type="custom" v-model="videos" name="@field.Name" :format="['mp4','flv','webm','ogv']" :min="@field.MinCount" :max="@field.MaxCount" :max-size="@Html.GetString(field.MaxLength > 0, (field.MaxLength * 1024).ToString(), "512000")">
                    @if (!string.IsNullOrEmpty(field.Remark))
                    {
                        <div slot="tip" class="tooltip-text">@Html.Raw(field.Remark)</div>
                    }
                    <i-button skin="primary">点击上传视频</i-button>
                    <ul slot="tip" v-if="videos.length" class="list am-padding-0 am-margin-0">
                        <li v-for="item in videos" :key="item.uid">
                            <a :href="item.url" target="blank">{{item.name}}</a>
                            <a @@click="handleRemoveVideo(item)" class="icon icon-x" style="color:red;margin-left:5px;" title="移除"></a>
                        </li>
                    </ul>
                </Upload>
                @*<UploadFile ref="@field.Name.ToLower()" name="@field.Name" :min="@field.MinCount" :max="@field.MaxCount" :max-length="@Html.GetString(field.MaxLength > 0, (field.MaxLength * 1024).ToString(), "512000")" :allow-ext="" tooltip="@field.Remark" />*@
            </div>
        }
    }
    else if (field.Type == MenuFieldType.Date.ToString() || field.Type == MenuFieldType.DateTime.ToString())
    {
        <datepicker type="@Html.GetString(field.Type == MenuFieldType.Date.ToString(), "date", "datetime")" name="@field.Name" value="@DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss")" placeholder="选择日期" style="width: 200px"></datepicker>
    }
    else if (field.Type == MenuFieldType.TextArea.ToString())
    {
        <textarea name="@field.Name" id="@fieldId" style="width:100%;height:60px" @Html.GetString(field.Required, "required", "")></textarea>
    }
    else if (field.Type == MenuFieldType.SmallEditor.ToString())
    {
        <editor ref="@field.Name.ToLower()" name="@field.Name" style="width:100%;height:60px" type="small" @Html.GetString(field.Required, "required", "") @@change="handleEditorChange"></editor>
        @*<textarea name="@field.Name" id="@fieldId" data-small></textarea>*@
    }
    else if (field.Type == MenuFieldType.Editor.ToString())
    {
        <editor ref="@field.Name.ToLower()" name="@field.Name" style="width:100%;height:300px" @@on-ready="editorReady" @@change="handleEditorChange" required></editor>
    }
</form-item>
    }
}